<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>混入 - {{ count }}</h2>
      <child></child>
    </div>

    <script src="../Vue.js"></script>
    <script>
      // 混入： 分发可复用功能
      // 创建混入对象,就是一个组件，仅仅就是没有template和el
      // 混入对象的内容和自身组件冲突的时候，以组件自身为准
      // 生命周期冲突，全部执行
      const myMixin = {
        data() {
          return {
            count: 10,
            name: "zhangjun",
          };
        },
        methods: {
          fn() {
            console.log("fn");
          },
        },
        created() {
          console.log("mixin created");
        },
      };

      const Child = {
        data() {
          return {
            name: "junjun",
          };
        },
        mixins: [myMixin],
        template: `
          <div>child组件 - {{ count }} - {{ name }}</div>
        `,
        mounted() {
          this.fn();
        },
        created() {
          console.log("child created");
        },
      };
      new Vue({
        el: "#app",
        mixins: [myMixin],
        components: {
          Child,
        },
      });
    </script>
  </body>
</html>
